package com.example.springcloud.controller;


import com.example.springcloudapi.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 消费者只需要controller 不需要其他层
 * 需要配置RestTemplate
 * RestTemplate供我们可以直接调用
 */
@Controller
public class DeptConsumerController {

    @Autowired
    private RestTemplate restTemplate;//提供多种便捷访问远程http的方法，简单的restful模板

//    private static final String REST_URL_PREFIX="http://localhost:8001";
private static final String REST_URL_PREFIX="http://SPRINGCLOUD-PROVIDER-DEPT";

@ResponseBody
@RequestMapping("/consumer/{id}")
public Dept get(@PathVariable("id") Long id){

        return restTemplate.getForObject(REST_URL_PREFIX+"/doDept/queryAllDeptByNo/"+id,Dept.class);
        }

@ResponseBody
@RequestMapping("/consumer/dept/getAll")
public List getAll(){

        return restTemplate.getForObject(REST_URL_PREFIX+"/doDept/queryAllDept",List.class);
        }

        }
